home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Windows Selection / Windows Selection 1.iso / Graphics / Formula Graphics Multimedia System / GAME_1.SXT < prev    next >
Encoding:
Text File  |  1996-04-02  |  5.4 KB  |  193 lines

  1. //////////////////////////
  2. // Harrow Software 1996
  3. // Example game script
  4. // Main script
  5. //
  6.  
  7. // This is an example of a sprite based game
  8. // The object is to shoot the never ending supply of colored balls
  9. // Notice that handles are freed after they are used
  10.  
  11. clear window color 100,100,100
  12.  
  13. start_game:
  14.  
  15.     // hide the mouse and set the position
  16.     // of the cursor to the centre of the screen
  17.     //
  18.     break mode OFF
  19.     mouse mode OFF
  20.     x_mid = GRAPHICS_WINDOW_XMAX/2
  21.     y_mid = GRAPHICS_WINDOW_YMAX/2
  22.     mouse position x_mid,y_mid
  23.  
  24.     // load all resources
  25.     //
  26.     call load_all_bitmaps
  27.     call load_sounds
  28.  
  29.     // prepare the good guy
  30.     //
  31.     good_guy_script = new script "game_2.sxt"
  32.     good_guy_script call initialize: @good_guy_bitmaps
  33.     good_guy_script call set_position: x_mid,y_mid
  34.  
  35.     // make lists for the colored balls and release 6 balls
  36.     //
  37.     colored_ball_scripts = new list
  38.     colored_ball_sprites = new list
  39.     for n = 1 to 6
  40.         call new_colored_ball
  41.  
  42.     // make lists for the cannon shots
  43.     //
  44.     cannon_shot_scripts = new list
  45.     cannon_shot_sprites = new list
  46.  
  47.     // start timing events
  48.     //
  49.     update_sprite_time = TIMER
  50.  
  51.     // detect messages from mouse and keyboard
  52.     //
  53.     win_msg = 0
  54.     while win_msg != WM_KEYDOWN && win_msg != WM_RBUTTONDOWN
  55.         peek message win_msg, wpm, x_parm, y_parm
  56.         switch win_msg
  57.  
  58.             case WM_LBUTTONDOWN
  59.                 play sound shooting_sound
  60.                 call shoot_cannon
  61.  
  62.             case WM_MOUSEMOVE
  63.                 x_off = x_parm - x_mid        // offset of mouse
  64.                 y_off = y_parm - y_mid
  65.                 if x_off || y_off
  66.                     //
  67.                     // if offset then move good guy
  68.                     //
  69.                     good_guy_script call offset_position: x_off,y_off
  70.                     mouse position x_mid,y_mid    // centre mouse again
  71.  
  72.         // update sprites 15 times per second
  73.         //
  74.         if TIMER > update_sprite_time + 7
  75.             update_sprite_time = TIMER
  76.  
  77.             // update the good guy
  78.             //
  79.             good_guy_script call update_sprite
  80.  
  81.             // update the cannon shots
  82.             // count down the list in case any shots get removed
  83.             //
  84.             cannon_shot_script = cannon_shot_scripts loop n mode LIST_DOWN
  85.                 state = cannon_shot_script call update_sprite
  86.                 if state == FALSE
  87.                     // find the position and remove the shot
  88.                     //
  89.                     pos = cannon_shot_scripts find @cannon_shot_script
  90.                     cannon_shot_scripts remove pos     // remove shot
  91.                     cannon_shot_sprites remove pos
  92.  
  93.                 // detect for collision with colored ball
  94.                 //
  95.                 cannon_shot_sprite = @cannon_shot_script.my_sprite
  96.                 other_sprite = sprite cannon_shot_sprite collision SPRITE_EXTERNAL loop m
  97.                     if $other_sprite.name == "colored ball"
  98.                         // get the position of the ball that was hit
  99.                         pos = colored_ball_sprites find @other_sprite
  100.                         colored_ball_scripts remove pos
  101.                         colored_ball_sprites remove pos
  102.                         cannon_shot_script call explode
  103.                         play sound exploding_sound
  104.                         call new_colored_ball
  105.  
  106.                 free cannon_shot_sprite    // free the handles
  107.                 free cannon_shot_script
  108.                 free other_sprite
  109.  
  110.             // update the colored balls
  111.             //
  112.             colored_ball_script = colored_ball_scripts loop n
  113.                 colored_ball_script call update_sprite
  114.             free colored_ball_script    // release the handle
  115.  
  116.             update sprites
  117.  
  118.     free all
  119.     update sprites
  120.     mouse mode ON
  121.     return
  122.  
  123. ///////////////
  124. new_colored_ball:
  125.     colored_ball_script = new script "game_3.sxt"
  126.     colored_ball_sprite = new sprite
  127.     colored_ball_script call initialize:\
  128.         @colored_ball_sprite, @colored_ball_bitmaps
  129.     colored_ball_scripts add colored_ball_script
  130.     colored_ball_sprites add colored_ball_sprite
  131.     free colored_ball_script    // free the handles
  132.     free colored_ball_sprite
  133.  
  134. //////////////
  135. shoot_cannon:
  136.     x,y,u,v = good_guy_script call get_shot_position
  137.     cannon_shot_script = new script "game_4.sxt"
  138.     cannon_shot_sprite = new sprite
  139.     cannon_shot_script call initialize: @cannon_shot_sprite, @cannon_shot_bitmaps, x,y,u,v
  140.     cannon_shot_scripts add cannon_shot_script
  141.     cannon_shot_sprites add cannon_shot_sprite
  142.     free cannon_shot_script
  143.     free cannon_shot_sprite
  144.  
  145. ////////////////////////////////////////////
  146. // Load files from disk and prepare them
  147. //
  148.  
  149. load_all_bitmaps:
  150.     files = new byte[10][32]
  151.     
  152.     // load the bitmaps for the colored balls
  153.     $files[0] = "ball_red";"ball_grn";"ball_blu";""
  154.     colored_ball_bitmaps = call load_bitmaps: @files
  155.  
  156.     // load the bitmaps for the cannon shot
  157.     $files[0] = "km_shot";"km_exp";"km_dust";""
  158.     cannon_shot_bitmaps = call load_bitmaps: @files
  159.  
  160.     // load the bitmaps for the good guy
  161.     $files[0] = "km_guy";"km_fire1";"km_fire2";""
  162.     good_guy_bitmaps = call load_bitmaps: @files
  163.  
  164.     // put all bitmaps on one list
  165.     all_bitmaps_list = new list
  166.     all_bitmaps_list add colored_ball_bitmaps
  167.     all_bitmaps_list add cannon_shot_bitmaps
  168.     all_bitmaps_list add good_guy_bitmaps
  169.  
  170.     // use a loop list to get a handle to every bitmap
  171.     // allocate palette positions and remap all bitmaps
  172.     // to the system palette
  173.     b = all_bitmaps_list loop n type "Bitmap" mode LIST_TREE
  174.         compose bitmap b
  175.         remap bitmap b
  176.         bitmap b transparency 0,255,0        // set the transparency color
  177.  
  178. /////////////////////// load bitmaps
  179. local load_bitmaps: files
  180.     bitmaps = new list                        // bitmap list
  181.     for n = 0 to 9
  182.         if !(files[n][0]) then break        // empty string
  183.         load $files[n], ".gif" bitmap b        // load a gif file
  184.         bitmaps add b                        // add it to the list
  185.     return @bitmaps
  186.  
  187. ///////////////// load sounds
  188. load_sounds:
  189.     load "shoot.wav" sound shooting_sound
  190.     load "explode.wav" sound exploding_sound
  191.  
  192. ///////////////////////////
  193. /////////////////////